CFE-2986: Added getdir command to cf-net, copies directory and files#6049
CFE-2986: Added getdir command to cf-net, copies directory and files#6049SimonThalvorsen wants to merge 1 commit intocfengine:masterfrom
Conversation
f7cebad to
40a6c09
Compare
larsewi
left a comment
There was a problem hiding this comment.
It would be nicer if we extended cf-net get to get both files and directories, instead of having two separate sub-commands. Please investigate how rsync does this and try to do it in a similar way here.
@larsewi on the other hand, cf-net was written mainly as a protocol testing tool, and the commands mirror their protocol command names. If the There is also some advantage to not being too dynamic with this stuff. If you make a CLI that forces the user to specify if they are copying a file or a folder, you can prevent some annoying / confusing situations. We could for example make a new subcommand, |
40a6c09 to
2bd2729
Compare
larsewi
left a comment
There was a problem hiding this comment.
Please break this up a little. Maybe a recursive solution would be more elegant given that it is a recursive problem.
2bd2729 to
e9f4cb3
Compare
e9f4cb3 to
5b55d16
Compare
larsewi
left a comment
There was a problem hiding this comment.
There should be a recursion depth limit to prevent a potential malicious or misconfigured server with symlink loops (or deeply nested dirs) to cause stack overflow.
We should probably stick to a maximum path size for the same reasons above.
d68100f to
047b068
Compare
larsewi
left a comment
There was a problem hiding this comment.
Make sure to check return values of functions. It's OK to do best effort. I.e., we encounter an error but continue if it's safe. But in this case we need to cache the error so that we can later exit with failure. For some errors, like if we fail to create a directory, it does not make sense to try to fetch the files that should be in that directory afterwards.
62eb2df to
c2b59c7
Compare
larsewi
left a comment
There was a problem hiding this comment.
It's starting to look good. Just a few more nitpicks. Almost there!
c2b59c7 to
38becec
Compare
Ticket: CFE-2986 Changelog: Title Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
38becec to
1b062de
Compare
larsewi
left a comment
There was a problem hiding this comment.
It's starting to look very good
| } | ||
| } | ||
|
|
||
| args = &(args[optind]); |
There was a problem hiding this comment.
There's no check that a positional argument remains. Running cf-net getdir -o /tmp/ (no remote dir) will probably dereference NULL
| return -1; | ||
| } | ||
|
|
||
| if (S_ISDIR(sb.st_mode)) // Is directory |
There was a problem hiding this comment.
Should probably skip non-regular files. Copying symlinks may have unexpected results. Maybe a verbose log message would also be nice.
if (!S_ISREG(sb.st_mode))
{
Log(LOG_LEVEL_VERBOSE, "Skipping non-regular file: %s", remote_full);
continue;
}
How does the cf-net get work? Does it copy symlinks?
| return ret; | ||
| } | ||
|
|
||
| static int CFNetGetDir(CFNetOptions *opts, const char *hostname, char **args) |
There was a problem hiding this comment.
Consider splitting this function up a bit if it makes sense
Ticket: CFE-2986
Changelog: Title